Skip to content

Fix SIGSEGV when reading an Object before it's been written (#5) - #6

Merged
urbanogilson merged 2 commits into
mainfrom
5-sigsegv-when-reading-object-before-write
Jul 28, 2026
Merged

Fix SIGSEGV when reading an Object before it's been written (#5)#6
urbanogilson merged 2 commits into
mainfrom
5-sigsegv-when-reading-object-before-write

Conversation

@urbanogilson

Copy link
Copy Markdown
Member

readObject/writeObject reinterpret raw Buffer memory directly as a Napi::Reference<Object>, with no check that the bytes actually hold a previously-written reference. Calling readObject on a buffer that was never written to (or filled with non-zero garbage) causes N-API to dereference a bogus handle, segfaulting the whole process.

This adds a magic-marker tag written by writeObject on first use. readObject now throws a catchable Error when the marker is missing, instead of dereferencing untrusted memory. writeObject on unmarked memory safely bootstraps a fresh reference in place.

@urbanogilson urbanogilson self-assigned this Jul 28, 2026
@urbanogilson urbanogilson linked an issue Jul 28, 2026 that may be closed by this pull request
@urbanogilson
urbanogilson merged commit 4c52713 into main Jul 28, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIGSEGV when reading object before write

1 participant